import axios from 'axios'
import './index'

const userBaseUrl = import.meta.env.VITE_BASE_URL

// 封装用户请求方式
function eventHttp({
  url,
  method,
  user_id,
  event_type,
  event_describe,
  event_handle_status,
  road_section_id,
  event_driver,
  event_car_number,
  event_date
}) {
  // console.log()
  return axios({
    url: userBaseUrl + url,
    method,
    data: {
      user_id,
      event_type,
      event_describe,
      event_handle_status,
      road_section_id,
      event_driver,
      event_car_number,
      event_date
    }
  })
}

// 封装获取所有事件
const getAllEventHttp = (page, size, keyword, status) => {
  if (!keyword) {
    keyword = ''
  }
  if (!status) {
    status = ''
  }
  return eventHttp({
    url: `/events?page=${page}&size=${size}&keyword=${keyword}&status=${status}`,
    method: 'get'
  })
}

// 封装获取单个事件的接口
const getOneEventHttp = (id) => {
  return eventHttp({
    url: `/events/${id}`,
    method: 'get'
  })
}

// 封装添加事件的接口
const postEventHttp = (
  user_id,
  event_type,
  event_describe,
  event_handle_status,
  road_section_id,
  event_driver,
  event_car_number
) => {
  return eventHttp({
    url: '/events',
    method: 'post',
    user_id,
    event_type,
    event_describe,
    event_handle_status,
    road_section_id,
    event_driver,
    event_car_number
  })
}

// 封装修改时间状态的接口
const putEventsStatusHttp = (id, event_handle_status) => {
  return eventHttp({
    url: `/events/${id}`,
    method: 'put',
    event_handle_status
  })
}

// 封装删除事件的接口
const deleteEventsHttp = (id) => {
  return eventHttp({
    url: `/events/${id}`,
    method: 'put'
  })
}

// 导出所有请求
export { getAllEventHttp, getOneEventHttp, postEventHttp, putEventsStatusHttp, deleteEventsHttp }
